//
//  ViewController.m
//  10802
//
//  Created by student on 16/2/23.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIPickerViewDataSource,UIPickerViewDelegate>
@property (weak, nonatomic) IBOutlet UIPickerView *pickView;
@property (weak, nonatomic) IBOutlet UILabel *infoLabel;
@property (weak, nonatomic) IBOutlet UIButton *btn;
@property (nonatomic,strong) NSArray *left;
@property (nonatomic,strong) NSArray *right;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.left = @[@"火腿",@"火鸡",@"花生酱",@"金枪鱼沙拉",@"鸡丁沙拉",@"烤牛肉",@"蔬菜"];
    self.right = @[@"白面包",@"粗面粉面包",@"黑麦面包",@"酸面包",@"天然有机7谷"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)btnPressed:(id)sender {
    int sel1 = [self.pickView selectedRowInComponent:0];
    int sel2 = [self.pickView selectedRowInComponent:1];
    self.infoLabel.text = [NSString stringWithFormat:@"我的早饭是%@和%@",self.left[sel1],self.right[sel2]];
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:[NSString stringWithFormat:@"您选择了%@和%@",self.left[sel1],self.right[sel2]] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:@"重新选择",nil];
    [alert show];
}


- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 2;
}

// returns the # of rows in each component..
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    if (component == 0)
    {
        return  self.left.count;
    }
    else
    {
        return self.right.count;
    }
}

- (nullable NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    if (component == 0)
    {
        return  self.left[row];
    }
    else
    {
        return self.right[row];
    }

}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    //[self.btn setTitle:[NSString stringWithFormat:@"选择%@%@",self.left[row],self.right[row]] forState:UIControlStateNormal];
}
@end
